package com.orm.mybatis.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Component
@EnableScheduling
public class Jobs {


    //表示方法执行完成后5秒
    @Scheduled(fixedDelay = 1000)
    public void fixedDelayJob() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread.sleep(105000);
        long end = System.currentTimeMillis();
        System.out.println("fixedDelay 每隔5秒结束" +"线程ID:"+Thread.currentThread().getId()+"----"+"耗费的时间："+(end-start)+"    "+ new SimpleDateFormat("HH-mm-ss").format(new Date()));
    }

    //表示每隔3秒
//    @Scheduled(fixedRate = 3000)
//    public void fixedRateJob() throws InterruptedException {
//        Thread.sleep(3000);
//        System.out.println("我是task2222fixedRate 每隔3秒结束" +"线程ID:"+Thread.currentThread().getId()+"----" +"    "+ new SimpleDateFormat("HH-mm-ss").format(new Date()));
//    }

    //表示每天8时30分0秒执行
    @Scheduled(cron = "0 0,30 0,8 ? * ? ")
    public void cronJob() {
        System.out.println(new Date() + " ...>>cron....");
    }

}
